//
//  PWPViewController.swift
//  TestPwp
//
//  Created by Denny on 2018/11/26.
//  Copyright © 2018 Denny. All rights reserved.
//

import Cocoa

class PWPViewController: NSViewController,NSTableViewDelegate,NSTableViewDataSource {

    @IBOutlet weak var contentView: NSView!
    @IBOutlet weak var tableView: NSTableView!
    
    @IBOutlet weak var scrollView: NSScrollView!
    
    @IBOutlet weak var arrowButton: NSButton!
    @IBOutlet weak var clipView: NSClipView!
    
    var oriRectRemember = CGRect.zero;
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do view setup here.
        
        let headerView = NSTableHeaderView.init(frame: NSRect.init(x: 0, y: 0, width: 200, height: 50));
        headerView.wantsLayer = true;
        headerView.layer?.backgroundColor = NSColor.red.cgColor;
//        self.tableView.headerView = headerView;
        
//        NSScrollView
        
        self.tableView.wantsLayer = true;
        self.tableView.backgroundColor = NSColor.clear;
//        self.tableView.layer?.backgroundColor = NSColor.red.cgColor;
        
        self.scrollView.wantsLayer = true;
        self.scrollView.backgroundColor = NSColor.clear;
//        self.scrollView.layer?.backgroundColor = NSColor.red.cgColor;
        
        self.clipView.wantsLayer = true;
        self.clipView.backgroundColor = NSColor.clear;
//        self.clipView.layer?.backgroundColor = NSColor.red.cgColor;
        
        self.arrowButton.wantsLayer = true;
        self.arrowButton.layer?.masksToBounds = true; self.arrowButton.layer?.backgroundColor = NSColor.orange.cgColor;
        
        
    }
    
    @IBAction func arrowAction(_ sender: Any) {
        
        if self.oriRectRemember == NSRect.zero {
            
            self.oriRectRemember = self.contentView.frame;
        }
        
        
        
        let oriRect = self.contentView.frame;
        
        if self.oriRectRemember != oriRect {
            
            self.contentView.animator().frame = self.oriRectRemember;
        }else{
            print(oriRect);
            
//            NSViewAnimation
            self.contentView.animator().frame = NSRect.init(x: oriRect.origin.x, y: oriRect.origin.y + 200, width: oriRect.size.width, height: oriRect.size.height - 200);
//            self.contentView.frame = NSRect.init(x: oriRect.origin.x, y: oriRect.origin.y + 200, width: oriRect.size.width, height: oriRect.size.height - 200);
        }
    }
    public func numberOfRows(in tableView: NSTableView) -> Int {
        
        //        ShowType.left
        return 100;
    }
    
    
    
    public func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
        
        
        
        let textField = NSTextField.init(string: "11111");
        textField.wantsLayer = true;
        textField.backgroundColor = NSColor.clear;
//        textField.layer?.backgroundColor = NSColor.blue.cgColor;
        textField.isBordered = false;
        return textField;
    }
    
//
//    public func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
//
//        let rowView = NSTableRowView.init();
//        return rowView;
//    }

    
    
}
